#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <fstream>
#include <set>

using namespace std;

void swap(char *start, char *end)
{
    char tmp;
    while (start < end) {
        tmp = *start;
        *start = *end;
        *end = tmp;
        start++;
        end--;
    }
}

void reverseWords(char *str)
{
    if (!str) return;
    char *s = str, *start = NULL;
    while (*str) {
        while(*str && *str == ' ') str++;
        if (start == NULL) start = str;
        while(*str && *str != ' ') str++;
        swap(start, str-1);
        start = NULL;
    }
    swap(s, str-1);
    return;
}


int main(int argc, char **argv)
{

    cout << "-----------------Test 1--------------------" << endl;
    char str[] = "hangyu is engineer";
    reverseWords(str);
    cout << str << endl;

    cout << "-----------------Test 2--------------------" << endl;

    cout << "-----------------Test 3--------------------" << endl;


    cout << "-----------------Test 4--------------------" << endl;


    cout << "-----------------Test 5--------------------" << endl;



}
